package com.shujia;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.NamespaceDescriptor;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;

public class Code01CreateNamespace {

    Connection connection;

    @Before
    public void getConnection(){
        Configuration configuration = new Configuration();

        // 注意：需要在当前平台中配置node1 node2的主机映射
        configuration.set("hbase.zookeeper.quorum","192.168.163.100,node1,node2");
        try {
            connection  = ConnectionFactory.createConnection(configuration);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Test
    public void createNameSpace(){
        try {

            // 对于Hbase中的元数据进行操作，可以直接使用admin对象
            Admin admin = connection.getAdmin();
//            NamespaceDescriptor.Builder builder = NamespaceDescriptor.create();
//            NamespaceDescriptor nsd = builder.build();

            NamespaceDescriptor nsd = NamespaceDescriptor.create("api").build();

            admin.createNamespace(nsd);


        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }


    @After
    public void close(){
        try {
            connection.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }


}
